public class MinInRotateArray {
    public int minNumberInRotateArray(int[] array) {
        // write code here
        int low = 0;
        int high = array.length - 1;
        while (low < high) {
            int mid = low + (high - low) / 2;
            if (array[mid] > array[high]) {
                low = mid + 1;
            } else if (array[mid] == array[high]) {
                high = high - 1;
            } else {
                high = mid;
            }
        }
        return array[low];
    }

    public int search(int[] nums, int target) {
        // write code here
        int low = 0, high = nums.length - 1;
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (nums[mid] == target)
                return mid;
            else if (nums[mid] < target)
                low = mid + 1;
            else high = mid - 1;
        }
        return -1;
    }


    public int compare(String version1, String version2) {
// write code here
// write code here
        String[] str1 = version1.split("\\.");
        String[] str2 = version2.split("\\.");
        int len = Math.max(str1.length, str2.length);
        for (int i = 0; i < len; i++) {
            String a = i < str1.length ? str1[i] : "0";
            String b = i < str2.length ? str2[i] : "0";
            for (int j = 0; j < a.length(); j++) {
                if (j == a.length() - 1 || a.charAt(j) != '0') {
                    a = a.substring(j);
                    break;
                }
            }
            for (int j = 0; j < b.length(); j++) {
                if (j == b.length() - 1 || b.charAt(j) != '0') {
                    b = b.substring(j);
                    break;
                }
            }
            if (a.length() > b.length()) {
                return 1;
            } else if (a.length() < b.length()) {
                return -1;
            } else {
                if (a.compareTo(b) > 0) {
                    return 1;
                } else if (a.compareTo(b) < 0) {
                    return -1;
                }
            }
        }
        return 0;
    }
}
